from subprocess import Popen, PIPE

class RunProcess:

    def __init__(self, DMRW, Klein, Zhang, cases, save):
        self.DMRW = DMRW
        self.Klein = Klein
        self.Zhang = Zhang
        self.cases = cases
        self.save = save

    def run(self):
        process = Popen(["external\TED no windows.exe"], stdin=PIPE, stdout=PIPE)
        self.testLine("Enter a path to save the results:", process)
        process.stdin.write(self.save + "\n")
        self.testLine("Would you like to use DMRW?(y/n)", process)
        self.choice(process, self.DMRW)
        self.testLine("Would you like to use Klein?(y/n)", process)
        self.choice(process, self.Klein)
        self.testLine("Would you like to use Shasha & Zhang?(y/n)", process)
        self.choice(process, self.Zhang)
        self.testLine("Would you like to load the test files", process)
        process.stdin.write("n\n")
        self.testLine("Enter how many tests would you like to run:", process)
        self.choice(process, self.cases + "\n")

    def testLine(self, line, process):
        while True:
            output = process.stdout.readline()
            print output
            if line in output:
                return

    def getDMRW(self):
        return self.DMRW

    def setDMRW(self, DMRW):
        self.DMRW = DMRW

    def getKlien(self):
        return self.Klein

    def setKlien(self, Klien):
        self.Klien = Klein

    def getZhang(self):
        return self.Zhang

    def setZhang(self, Zhang):
        self.Zhang = Zhang

    def getCases(self):
        return self.cases

    def setCases(self, cases):
        self.cases = cases

    def getSave(self):
        return self.save

    def setSave(self, save):
        self.save = save

    def choice(self, process, option):
        if option:
            process.stdin.write("y\n")
        else:
            process.stdin.write("n\n")
